home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 1999 #5 / 1999 CD 5 (black).iso / Delphi3 / install / data.z / TLHELP32.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-08-04  |  6.2 KB  |  182 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Delphi Runtime Library                          }
  5. {       Tool Help Functions, Types, and Definitions     }
  6. {                                                       }
  7. {       Copyright (c) 1996,97 Borland International     }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit TLHelp32;
  12.  
  13. {$WEAKPACKAGEUNIT}
  14.  
  15. interface
  16.  
  17. uses Windows;
  18.  
  19. const
  20.   MAX_MODULE_NAME32 = 255;
  21.  
  22. (****** Shapshot function **********************************************)
  23.  
  24. function CreateToolhelp32Snapshot(dwFlags, th32ProcessID: DWORD): THandle; stdcall;
  25. //
  26. // The th32ProcessID argument is only used if TH32CS_SNAPHEAPLIST or
  27. // TH32CS_SNAPMODULE is specified. th32ProcessID == 0 means the current
  28. // process.
  29. //
  30. // NOTE that all of the snapshots are global except for the heap and module
  31. //    lists which are process specific. To enumerate the heap or module
  32. //    state for all WIN32 processes call with TH32CS_SNAPALL and the
  33. //    current process. Then for each process in the TH32CS_SNAPPROCESS
  34. //    list that isn't the current process, do a call with just
  35. //    TH32CS_SNAPHEAPLIST and/or TH32CS_SNAPMODULE.
  36. //
  37. // dwFlags
  38. //
  39. const
  40.   TH32CS_SNAPHEAPLIST = $00000001;
  41.   TH32CS_SNAPPROCESS  = $00000002;
  42.   TH32CS_SNAPTHREAD   = $00000004;
  43.   TH32CS_SNAPMODULE   = $00000008;
  44.   TH32CS_SNAPALL      = TH32CS_SNAPHEAPLIST or TH32CS_SNAPPROCESS or
  45.     TH32CS_SNAPTHREAD or TH32CS_SNAPMODULE;
  46.   TH32CS_INHERIT      = $80000000;
  47. //
  48. // Use CloseHandle to destroy the snapshot
  49. //
  50.  
  51. (****** heap walking ***************************************************)
  52.  
  53. type
  54.   PHeapList32 = ^THeapList32;
  55.   THeapList32 = record
  56.     dwSize: DWORD;
  57.     th32ProcessID: DWORD;  // owning process
  58.     th32HeapID: DWORD;     // heap (in owning process's context!)
  59.     dwFlags: DWORD;
  60.   end;
  61. //
  62. // dwFlags
  63. //
  64. const
  65.   HF32_DEFAULT = 1;  // process's default heap
  66.   HF32_SHARED  = 2;  // is shared heap
  67.  
  68. function Heap32ListFirst(hSnapshot: THandle; var lphl: THeapList32): BOOL; stdcall;
  69. function Heap32ListNext(hSnapshot: THandle; var lphl: THeapList32): BOOL; stdcall;
  70.  
  71. type
  72.   PHeapEntry32 = ^THeapEntry32;
  73.   THeapEntry32 = record
  74.     dwSize: DWORD;
  75.     hHandle: THandle;     // Handle of this heap block
  76.     dwAddress: DWORD;      // Linear address of start of block
  77.     dwBlockSize: DWORD;   // Size of block in bytes
  78.     dwFlags: DWORD;
  79.     dwLockCount: DWORD;
  80.     dwResvd: DWORD;
  81.     th32ProcessID: DWORD; // owning process
  82.     th32HeapID: DWORD;    // heap block is in
  83.   end;
  84. //
  85. // dwFlags
  86. //
  87. const
  88.   LF32_FIXED    = $00000001;
  89.   LF32_FREE     = $00000002;
  90.   LF32_MOVEABLE = $00000004;
  91.  
  92. function Heap32First(var lphe: THeapEntry32; th32ProcessID,
  93.   th32HeapID: DWORD): BOOL; stdcall;
  94. function Heap32Next(var lphe: THeapEntry32): BOOL; stdcall;
  95. function Toolhelp32ReadProcessMemory(th32ProcessID: DWORD;
  96.   lpBaseAddress: Pointer; var lpBuffer; cbRead: DWORD;
  97.   var lpNumberOfBytesRead: DWORD): BOOL; stdcall;
  98.  
  99. (***** Process walking *************************************************)
  100.  
  101. type
  102.   PProcessEntry32 = ^TProcessEntry32;
  103.   TProcessEntry32 = record
  104.     dwSize: DWORD;
  105.     cntUsage: DWORD;
  106.     th32ProcessID: DWORD;       // this process
  107.     th32DefaultHeapID: DWORD;
  108.     th32ModuleID: DWORD;        // associated exe
  109.     cntThreads: DWORD;
  110.     th32ParentProcessID: DWORD; // this process's parent process
  111.     pcPriClassBase: Longint;    // Base priority of process's threads
  112.     dwFlags: DWORD;
  113.     szExeFile: array[0..MAX_PATH - 1] of Char;// Path
  114.   end;
  115.  
  116. function Process32First(hSnapshot: THandle; var lppe: TProcessEntry32): BOOL; stdcall;
  117. function Process32Next(hSnapshot: THandle; var lppe: TProcessEntry32): BOOL; stdcall;
  118.  
  119. (***** Thread walking **************************************************)
  120.  
  121. type
  122.   PThreadEntry32 = ^TThreadEntry32;
  123.   TThreadEntry32 = record
  124.     dwSize: DWORD;
  125.     cntUsage: DWORD;
  126.     th32ThreadID: DWORD;       // this thread
  127.     th32OwnerProcessID: DWORD; // Process this thread is associated with
  128.     tpBasePri: Longint;
  129.     tpDeltaPri: Longint;
  130.     dwFlags: DWORD;
  131.   end;
  132.  
  133. function Thread32First(hSnapshot: THandle; var lpte: TThreadEntry32): BOOL; stdcall;
  134. function Thread32Next(hSnapshot: THandle; var lpte: TThreadENtry32): BOOL; stdcall;
  135.  
  136. (***** Module walking *************************************************)
  137.  
  138. type
  139.   PModuleEntry32 = ^TModuleEntry32;
  140.   TModuleEntry32 = record
  141.     dwSize: DWORD;
  142.     th32ModuleID: DWORD;  // This module
  143.     th32ProcessID: DWORD; // owning process
  144.     GlblcntUsage: DWORD;  // Global usage count on the module
  145.     ProccntUsage: DWORD;  // Module usage count in th32ProcessID's context
  146.     modBaseAddr: PBYTE;   // Base address of module in th32ProcessID's context
  147.     modBaseSize: DWORD;   // Size in bytes of module starting at modBaseAddr
  148.     hModule: HMODULE;     // The hModule of this module in th32ProcessID's context
  149.     szModule: array[0..MAX_MODULE_NAME32] of Char;
  150.     szExePath: array[0..MAX_PATH - 1] of Char;
  151.   end;
  152.  
  153. //
  154. // NOTE CAREFULLY that the modBaseAddr and hModule fields are valid ONLY
  155. // in th32ProcessID's process context.
  156. //
  157.  
  158. function Module32First(hSnapshot: THandle; var lpme: TModuleEntry32): BOOL; stdcall;
  159. function Module32Next(hSnapshot: THandle; var lpme: TModuleEntry32): BOOL; stdcall;
  160.  
  161. implementation
  162.  
  163. const
  164.   kernel32 = 'kernel32.dll';
  165.  
  166. function CreateToolhelp32Snapshot; external kernel32 name 'CreateToolhelp32Snapshot';
  167. function Heap32ListFirst; external kernel32 name 'Heap32ListFirst';
  168. function Heap32ListNext; external kernel32 name 'Heap32ListNext';
  169. function Heap32First; external kernel32 name 'Heap32First';
  170. function Heap32Next; external kernel32 name 'Heap32Next';
  171. function Toolhelp32ReadProcessMemory; external kernel32 name 'Toolhelp32ReadProcessMemory';
  172. function Process32First; external kernel32 name 'Process32First';
  173. function Process32Next; external kernel32 name 'Process32Next';
  174. function Thread32First; external kernel32 name 'Thread32First';
  175. function Thread32Next; external kernel32 name 'Thread32Next';
  176. function Module32First; external kernel32 name 'Module32First';
  177. function Module32Next; external kernel32 name 'Module32Next';
  178.  
  179. end.
  180.  
  181.  
  182.